// pages/user/user/userMsg/userMsg.js
const app = getApp();
import Api from '../../../../utils/http';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    systemMsg: '',//系统消息
    newsMsg:'',//新闻及通告
  },
  //消息列表
  toMsgList: function(e){
    var type = e.currentTarget.dataset.type;//1 为系统消息，2 为新闻及通告
    console.log(type);
    wx.navigateTo({
      url: '/pages/user/user/userMsgList/userMsgList?type='+type,
    });
    this.getSeeMsg(e);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getsystemMsg();
    this.grtnewsMsg();
  },
  //系统消息
  getsystemMsg: function (options) {
    var that = this;
    let uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type: uid.user_type,
      type: 1,
      pageNum: 1,
      pageSize: 1,
    }
    console.log(param)
    Api.ajax("/app/Zpersonalcenter/msgList", param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          systemMsg: res.data
        });
      }
    })
  },
  //新闻及通告
  grtnewsMsg: function (options) {
    var that = this;
    let uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type: uid.user_type,
      type: 2,
      pageNum: 1,
      pageSize: 1,
    }
    console.log(param)
    Api.ajax("/app/Zpersonalcenter/msgList", param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          newsMsg: res.data
        });
      }
    })
  },
  //查看消息
  getSeeMsg: function (e) {
    var that = this;
    let uid = wx.getStorageSync('userid');
    console.log(that.data,e);
    var param = {
      uid: uid.id,
      user_type:uid.user_type,
      type: parseInt(e.currentTarget.dataset.type),
    }
    console.log(param)
    Api.ajax("/app/Zpersonalcenter/msgLook", param).then(res => {
      console.log(res)
      if (res.code == 200) {
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})